<?php
class Crypteur {
 
    private $cle;
 
    public function __construct($cle)
    {
        $this->cle = substr($cle, 0, mcrypt_get_key_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB));
    }
 
    public function crypte($donnee)
    {
        if(!$donnee)
        {
            return false;
        }
 
        $crypted = mcrypt_encrypt(MCRYPT_BLOWFISH, $this->cle, htmlspecialchars($donnee), MCRYPT_MODE_ECB);
        return trim(base64_encode($crypted));
    }
 
    public function decrypte($donnee)
    {
        if(!$donnee)
        {
            return false;
        }
 
        $crypted = base64_decode($donnee);
 
        $decrypted = mcrypt_decrypt(MCRYPT_BLOWFISH, $this->cle, $crypted, MCRYPT_MODE_ECB);
        return htmlspecialchars(trim($decrypted));
 
    }
 
}
?>